package com.example.staticdemo.controller;

import com.example.staticdemo.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private TestService testService;

//    @GetMapping("/demo")
//    public String demo() {
//        return "demo";
//    }

    @GetMapping("/silkToWav")
    public Object silkToWav(@RequestParam(value = "sourceFileDir",defaultValue = "/home/2023030302") String sourceFile,
                          @RequestParam(value = "targetFile",defaultValue = "/home/2023030302") String targetFile,
                          @RequestParam(value = "sh",defaultValue = "/home/silk-v3-decoder-master/converter.sh") String sh){


        new Thread(new Runnable() {
            @Override
            public void run() {
                testService.silkToWav(sourceFile,targetFile,sh);
            }
        }).start();
        return null;
    }

    @GetMapping("/pcmToWav")
    public Object pcmToWav(@RequestParam(value = "sourceFileDir",defaultValue = "/home/2023030302") String sourceFileDir,
                          @RequestParam(value = "targetFileDir",defaultValue = "/home/2023030302") String targetFileDir,
                          @RequestParam(value = "sh",defaultValue = "/home/silk-v3-decoder-master/converter.sh") String sh){
        new Thread(new Runnable() {
            @Override
            public void run() {
                testService.pcmToWav(sourceFileDir,targetFileDir,sh);
            }
        }).start();
        return null;
    }
}
